import { JSEncrypt } from 'jsencrypt'

// 公钥
const publicKey = `-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1WWlAM+C9uZWA/aF5ScF
LskeppNgjwYDEPjkhkfFr4Ue+DExv/rVKjjx3rKup2Rk2K2bm8TQVL9yWg+ELF8k
LTtpf97X2UECLUQcOabzjX17E9vyHtYzF0tWnRgiOesPfWQ5z67vn+FaJrEFwD+1
bR83Bfi8OT6JjQzEkiQ2WDQI+Jl4cKL7l6Zr0jdnGdeAY1d66bOUfcM4E7ORvAfG
Usb0kMkoVs62zLPpWU+c7yhuNQLU7gcGcessZ8gYjybCyJIJgRMXe/zIvU1zhWYp
2klK9JmZiintaeW+UathnAz3QKcw5MUbzYrGRLcVqEZaJpbq0Kf43r5xTwQDl2qR
owIDAQAB
-----END PUBLIC KEY-----`

// 私钥
const privateKey = `-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDVZaUAz4L25lYD
9oXlJwUuyR6mk2CPBgMQ+OSGR8WvhR74MTG/+tUqOPHesq6nZGTYrZubxNBUv3Ja
D4QsXyQtO2l/3tfZQQItRBw5pvONfXsT2/Ie1jMXS1adGCI56w99ZDnPru+f4Vom
sQXAP7VtHzcF+Lw5PomNDMSSJDZYNAj4mXhwovuXpmvSN2cZ14BjV3rps5R9wzgT
s5G8B8ZSxvSQyShWzrbMs+lZT5zvKG41AtTuBwZx6yxnyBiPJsLIkgmBExd7/Mi9
TXOFZinaSUr0mZmKKe1p5b5Rq2GcDPdApzDkxRvNisZEtxWoRlomlurQp/jevnFP
BAOXapGjAgMBAAECggEAeOCZxcrF0ZuJz7beA37F5cmQ7iR/RqTOKdgCgrm3FgRf
FZGwL6IjC0a0Y0RtwG4S3dYBVgv3QnoriS5O3V+LO3/y87bEJ9E2LXPuVQ3n2hbh
F8+355XH3QMU7emUwaAP5yRVxvm9zJ+3FEGkE1FD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PRIVATE KEY-----`

//  加密
function encrypt(data: any) {
  // 新建JSEncrypt对象
  const encryptor = new JSEncrypt()
  // 设置公钥
  encryptor.setPublicKey(publicKey)
  // 加密数据
  return encryptor.encrypt(data)
}
// 解密
function decrypt(data: any) {
  // 新建JSEncrypt对象
  const decrypt = new JSEncrypt()
  // 设置私钥
  decrypt.setPrivateKey(privateKey)
  // 解密数据
  return decrypt.decrypt(data)
}

export { encrypt, decrypt }
